<?php
/**
 * 熵巡 - 企业级氚云OpenAPI数据管理平台
 * 开发归属 Alyr.net
 * 获取用户配置接口 - 管理员信息读取
 * 尊重劳动成果是一种美德
 */

header('Content-Type: application/json');

try {
    $configFile = __DIR__ . '/../config.php';
    
    if (!file_exists($configFile)) {
        echo json_encode(['success' => false, 'message' => '配置文件不存在']);
        exit;
    }
    
    $config = include $configFile;
    
    if (isset($config['admin_user'])) {
        $userData = [
            'username' => $config['admin_user']['username'],
            'phone' => $config['admin_user']['phone'] ?? '',
            'dingtalk_id' => $config['admin_user']['dingtalk_id'] ?? '',
            'wechat_id' => $config['admin_user']['wechat_id'] ?? '',
            'feishu_id' => $config['admin_user']['feishu_id'] ?? '',
            // 出于安全考虑，密码不返回给前端
        ];
    } else {
        // 配置不存在时返回默认值
        $userData = [
            'username' => 'admin',
            'phone' => '',
            'dingtalk_id' => '',
            'wechat_id' => '',
            'feishu_id' => '',
        ];
    }
    
    echo json_encode([
        'success' => true,
        'data' => $userData,
        'plugins' => [
            'sms' => [
                'enabled' => $config['plugins']['sms']['enabled'] ?? false
            ],
            'dingtalk' => [
                'enabled' => $config['plugins']['dingtalk']['enabled'] ?? false
            ],
            'wechat' => [
                'enabled' => $config['plugins']['wechat']['enabled'] ?? false
            ],
            'feishu' => [
                'enabled' => $config['plugins']['feishu']['enabled'] ?? false
            ]
        ]
    ]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => '获取配置失败: ' . $e->getMessage()]);
}
exit;